
use clap::Parser;
use crate::errors::RuntimeError;


#[derive(Debug, Parser, Default)]
pub struct Args {
    #[arg(short, long, default_value = "config.toml")]
    pub config_path: String,
    
    #[arg(short, long, default_value = "60")]
    pub memory_fresh_tick: u64,

    #[arg(short, long)]
    pub version: bool
}

impl Args {
    pub fn check(&self) -> Result<(), RuntimeError> {
        if self.version {
            return Ok(());
        }
        if self.memory_fresh_tick == 0 {
            return Err(RuntimeError::InvalidConfParam((&self.memory_fresh_tick).to_string()));
        }
        match &self.config_path {
            path if path.is_empty() => {
                return Err(RuntimeError::InvalidConfParam((&self.config_path).to_string()));
            }
            _ => {}
        }
        if let Ok(file_matadata) = std::fs::metadata(&self.config_path){
            if std::fs::Metadata::is_file(&file_matadata) {
                return Ok(());
            }
        }
        return  Err(RuntimeError::InvalidConfParam((&self.config_path).to_string()));
    }
}